package com.moonshineproject.plugin.haxe.haxeproject.importer
{
	import com.moonshineproject.plugin.core.importer.FlashDevelopImporterBase;
	import com.moonshineproject.plugin.haxe.haxeproject.vo.HaXeProjectVO;
	import com.moonshineproject.utils.Utils;
	
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	public class HaXeFlashDevelopImporter extends FlashDevelopImporterBase
	{
		public static function parse(file:File):HaXeProjectVO
		{
			var folder:File = file.parent;
			
			var p:HaXeProjectVO = new HaXeProjectVO(folder);
			p.projectFile = file;
			
			// Open file for parsing
			var stream:FileStream = new FileStream();
			stream.open(file, FileMode.READ);
			var data:XML = XML(stream.readUTFBytes(file.size));
			stream.close();
			
			// Parse XML
			p.swfOutput.parse(data.output, p.folder);
			p.buildOptions.parse(data.build);
			
			parsePaths(data.classpaths["class"], p.classpaths, p);
			parsePaths(data.haxelib.library, p.haxelib, p, "name");
			parsePaths(data.compileTargets.compile, p.targets, p);
			
			p.assetLibrary = data.library;
			parsePaths(data.hiddenPaths.hidden, p.hiddenPaths, p);
			
			p.showHiddenPaths = Utils.deserializeBoolean(data.options.option.@showHiddenPaths);
			p.testMovie = data.options.option.@testMovie;
			p.postbuildAlways = Utils.deserializeBoolean(data.postBuildCommand.@alwaysRun);
			
			p.prebuildCommands = Utils.deserializeString(data.preBuildCommand);
			p.postbuildCommands = Utils.deserializeString(data.postBuildCommand);
			
			return p;	
		}
		
	}
}